package com.jz.community.moduleshoppingguide.home.ui.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.base.BaseX5WebActivity;
import com.jz.community.basecomm.net.retrofit.BaseRxObserver;
import com.jz.community.basecomm.routerUtils.RouterCommonUtils;
import com.jz.community.basecomm.routerUtils.RouterIntentConstant;
import com.jz.community.basecomm.utils.BaseUserUtils;
import com.jz.community.moduleshoppingguide.R;
import com.jz.community.moduleshoppingguide.home.bean.HomeFindBean;
import com.jz.community.moduleshoppingguide.home.bean.ShareBean;
import com.jz.community.moduleshoppingguide.home.model.ShoppingModelGuideImpl;
import com.jz.community.moduleshoppingguide.home.ui.activity.BestSellersActivity;
import com.jz.community.moduleshoppingguide.home.ui.activity.ChannelOutActivity;
import com.jz.community.moduleshoppingguide.home.ui.activity.PreferentialActivity;
import com.jz.community.moduleshoppingguide.nearshop.ui.activity.NearShopActivity;
import com.jz.community.moduleshoppingguide.neighbor.ui.activity.NeighborMainActivity;

import java.util.List;


public class HomeMainMenuAdapter extends BaseQuickAdapter<HomeFindBean.EmbeddedBean.ContentBean.ChunnelHomePageBean, BaseViewHolder> {


    public HomeMainMenuAdapter(int layoutResId, @Nullable List<HomeFindBean.EmbeddedBean.ContentBean.ChunnelHomePageBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeFindBean.EmbeddedBean.ContentBean.ChunnelHomePageBean entity) {
        TextView menu_title = helper.getView(R.id.item_home_menu_tv);
        ImageView imageView = helper.getView(R.id.item_home_menu_iv);
        Glide.with(mContext)
                .load(entity.getImage())
                .into(imageView);
        menu_title.setText(entity.getName());

        //13:京东商城,14:苏宁易购,15:网易严选,16:自提购
        if ("4".equals(entity.getType())) {
            imageView.setOnClickListener(v -> {
                Intent intent = new Intent(mContext, PreferentialActivity.class);
                mContext.startActivity(intent);
            });
        } else if ("9".equals(entity.getType())) {
            imageView.setOnClickListener(v -> {
                Intent intent = new Intent(mContext, NearShopActivity.class);
                mContext.startActivity(intent);
            });
        } else if ("7".equals(entity.getType())) {
            imageView.setOnClickListener(v -> {
                if (BaseUserUtils.getIsLogin(mContext)) {
                    Intent intent = new Intent(mContext, NeighborMainActivity.class);
                    mContext.startActivity(intent);
                } else {
                    ARouter.getInstance().build(RouterIntentConstant.MODULE_AUTHORIZATION_LOGIN).navigation();
                }
            });
        } else if ("5".equals(entity.getType())) {
            imageView.setOnClickListener(v -> {
                if (BaseUserUtils.getIsLogin(mContext)) {
                    RouterCommonUtils.startNoParameterActivity(RouterIntentConstant.INTEGRAL_GOODS);
                } else {
                    ARouter.getInstance().build(RouterIntentConstant.MODULE_AUTHORIZATION_LOGIN).navigation();
                }
            });
        } else if ("2".equals(entity.getType())) {
            imageView.setOnClickListener(v -> RouterCommonUtils.startNoParameterActivity(RouterIntentConstant.CARD_HOME));
        } else if ("1".equals(entity.getType())) {
            imageView.setOnClickListener(v -> {
                Intent intent = new Intent(mContext, BestSellersActivity.class);
                intent.putExtra("name", entity.getName());
                intent.putExtra("message", 1);
                mContext.startActivity(intent);
            });
        } else if ("6".equals(entity.getType())) {
            imageView.setOnClickListener(v -> {
                if (BaseUserUtils.getIsLogin(mContext)) {
                    RouterCommonUtils.startNoParameterActivity(RouterIntentConstant.RECHARGE_PHONE);
                } else {
                    ARouter.getInstance().build(RouterIntentConstant.MODULE_AUTHORIZATION_LOGIN).navigation();
                }
            });

        } else if ("11".equals(entity.getType())) {
            imageView.setOnClickListener(v -> new ShoppingModelGuideImpl(mContext).initShareGift(new BaseRxObserver<ShareBean>() {
                @Override
                public void onSuccess(ShareBean shareBean) {
                    mContext.startActivity(new Intent(mContext, BaseX5WebActivity.class)
                            .putExtra("url", shareBean.getData())
                            .putExtra("title", "分享有礼"));
                }
            }));
        } else if ("13".equals(entity.getType())) {
            imageView.setOnClickListener(v -> {
                Intent intent = new Intent(mContext, ChannelOutActivity.class);
                intent.putExtra("name", entity.getName());
                intent.putExtra("id", entity.getShowGoodsCategoryId());
                intent.putExtra("shopId", entity.getShopId());
                mContext.startActivity(intent);
            });
        } else if ("14".equals(entity.getType())) {
            imageView.setOnClickListener(v -> {
                Intent intent = new Intent(mContext, ChannelOutActivity.class);
                intent.putExtra("name", entity.getName());
                intent.putExtra("id", entity.getShowGoodsCategoryId());
                intent.putExtra("shopId", entity.getShopId());
                mContext.startActivity(intent);
            });
        } else if ("15".equals(entity.getType())) {

            imageView.setOnClickListener(v -> {
                Intent intent = new Intent(mContext, ChannelOutActivity.class);
                intent.putExtra("name", entity.getName());
                intent.putExtra("id", entity.getShowGoodsCategoryId());
                intent.putExtra("shopId", entity.getShopId());
                mContext.startActivity(intent);
            });
        } else if ("8".equals(entity.getType())) {

            imageView.setOnClickListener(v -> {
                Intent intent = new Intent(mContext, ChannelOutActivity.class);
                intent.putExtra("name", entity.getName());
                intent.putExtra("id", entity.getShowGoodsCategoryId());
                intent.putExtra("shopId", entity.getShopId());
                mContext.startActivity(intent);
            });
        } else if ("16".equals(entity.getType())) {

            imageView.setOnClickListener(v -> {
                Intent intent = new Intent(mContext, BestSellersActivity.class);
                intent.putExtra("name", entity.getName());
                intent.putExtra("message", 2);
                mContext.startActivity(intent);
            });
        }
    }
}
